package com.ssy.lingxi.marketing.controller.activity;

import com.ssy.lingxi.common.constant.marketing.ActivityTypeEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.SelectItemVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.model.constant.PlatformActivitySignUpInnerStatusEnum;
import com.ssy.lingxi.marketing.model.constant.PlatformActivitySignUpOuterStatusEnum;
import com.ssy.lingxi.marketing.model.vo.activity.request.*;
import com.ssy.lingxi.marketing.model.vo.activity.response.*;
import com.ssy.lingxi.marketing.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.marketing.model.vo.coupon.request.ActivityMerchantPrizeCouponRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.ActivityMerchantSubsidiaryCouponRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityGoodsCouponResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityPrizeCouponResponse;
import com.ssy.lingxi.marketing.service.ICommonService;
import com.ssy.lingxi.marketing.service.IMerchantCouponService;
import com.ssy.lingxi.marketing.service.IPlatformActivitySignUpService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;

/**
 * @menu 营销能力-平台营销活动报名
 * @author ds, yzc
 * @date 2021/6/18
 * @version 2.0.0
 */
@RestController
@RequestMapping("/marketing/platform/activity/signup")
public class PlatformActivitySignUpController extends BaseController {

    @Resource
    private IPlatformActivitySignUpService platformActivitySignUpService;
    @Resource
    private ICommonService commonService;
    @Resource
    private BaseActivityRecordService activityRecordService;
    @Resource
    private IMerchantCouponService merchantCouponService;

    /**
     * 平台营销活动查询 - 外部状态列表
     */
    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return commonService.getStatusList(PlatformActivitySignUpOuterStatusEnum.class);
    }

    /**
     * 平台营销活动查询 - 内部状态列表
     */
    @RequestMapping(value = "/getInnerStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getStatusList() {
        return commonService.getStatusList(PlatformActivitySignUpInnerStatusEnum.class);
    }

    /**
     * 平台营销活动查询 - 活动类型列表
     */
    @RequestMapping(value = "/getActivityTypeList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getActivityTypeList() {
        return commonService.getStatusList(ActivityTypeEnum.class, Collections.singletonList(ActivityTypeEnum.LOTTERY.getCode()));
    }

    /**
     * 平台营销活动查询 - 分页列表
     **/
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpPageResp>> pageSummary(HttpServletRequest httpRequest, @Valid PfActivitySignUpPageReq pageVO) {
        return platformActivitySignUpService.pageSummary(getSysUser(httpRequest), pageVO);
    }

    /**
     * 平台营销活动查询 - 活动详情
     **/
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<PfActivitySignUpDetailResp> detail(@RequestParam("activityId") Long activityId) {
        return platformActivitySignUpService.detail(getSysUser(), activityId);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 活动商品(分页)
     **/
    @RequestMapping(value = "/detail/goods/page", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpGoodsPageResp>> activityGoodsPage(HttpServletRequest httpRequest, @Valid PfActivitySignUpGoodsPageReq pageVO) {
        return platformActivitySignUpService.pageByActivityGoods(getSysUser(httpRequest), pageVO);
    }

    /**
     * 平台营销活动查询 - 活动详情 - 活动商品 - 选择附属优惠券查询条件
     * @return 返回结果
     */
    @RequestMapping(value = "/detail/goods/coupon/select/condition", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> selectSubsidiaryCouponCondition() {
        return merchantCouponService.selectSubsidiaryCouponCondition();
    }

    /**
     * 平台营销活动查询 - 活动详情 - 活动商品 - 选择附属优惠券
     **/
    @RequestMapping(value = "/detail/goods/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityGoodsCouponResponse>> selectSubsidiaryCouponList(HttpServletRequest httpRequest, ActivityMerchantSubsidiaryCouponRequest request) {
        return merchantCouponService.selectSubsidiaryCouponList(request, getSysUser(httpRequest));
    }

    /**
     * 平台营销活动查询 - 活动详情 - 奖品 - 选择0元购买抵扣券
     **/
    @RequestMapping(value = "/detail/prize/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityPrizeCouponResponse>> selectPrizeCouponList(HttpServletRequest httpRequest, ActivityMerchantPrizeCouponRequest request) {
        return merchantCouponService.selectPrizeCouponList(request, getSysUser(httpRequest));
    }

    /**
     * 平台营销活动查询 - 详情 - 外部流转记录(分页)
     */
    @RequestMapping(value = "/detail/outer/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityOuterRecordResp>> pageOuterRecordList(HttpServletRequest httpRequest, @Valid ActivityOuterRecordPageReq pageVO) {
        return activityRecordService.pagePlatformActivitySignUpOuterRecord(getSysUser(httpRequest), pageVO);
    }

    /**
     * 平台营销活动查询 - 详情 - 内部流转记录(分页)
     */
    @RequestMapping(value = "/detail/inner/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityInnerRecordResp>> pageInnerRecordList(HttpServletRequest httpRequest, @Valid ActivityInnerRecordPageReq pageVO) {
        return activityRecordService.pagePlatformActivitySignUpInnerRecord(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核报名资料 - 分页列表
     **/
    @RequestMapping(value = "/page/tobe/submit", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpSubmitExamPageResp>> pageByToBeSubmit(HttpServletRequest httpRequest, @Valid PfActivitySignUpPageReq pageVO) {
        return platformActivitySignUpService.pageByToBeSubmit(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核报名资料 - 填写报名资料
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Wrapper<Void> save(HttpServletRequest httpRequest, @RequestBody @Valid PfActivitySignUpAddReq pageVO) {
        return platformActivitySignUpService.save(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核报名资料 - 修改报名资料
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(HttpServletRequest httpRequest, @RequestBody @Valid PfActivitySignUpUpdateReq pageVO) {
        return platformActivitySignUpService.update(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核报名资料 - 查询活动商品过滤的skuId
     */
    @PostMapping(value = "/getFilterSkuId")
    public Wrapper<FilterSkuIdResponse> getFilterSkuId(@RequestBody @Valid FilterSkuIdRequest req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return platformActivitySignUpService.getFilterSkuId(loginUser, req);
    }

    /**
     * 待提交审核报名资料 - 提交审核
     **/
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public Wrapper<Void> submitExamine(HttpServletRequest httpRequest, @RequestBody @Valid PfActivityExamineSubmitReq submitReq) {
        return platformActivitySignUpService.submitExamine(getSysUser(httpRequest), submitReq);
    }

    /**
     * 待提交审核报名资料 - 批量提交
     **/
    @RequestMapping(value = "/submit/batch", method = RequestMethod.POST)
    public Wrapper<Void> submitExamineBatch(HttpServletRequest httpRequest, @RequestBody @Valid PfActivitySingUpIdsReq req) {
        return platformActivitySignUpService.submitExamineBatch(getSysUser(httpRequest), req);
    }

    /**
     * 待审核报名资料(一级) - 分页列表
     **/
    @RequestMapping(value = "/page/tobe/examine/step1", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpExamPageResp>> pageByToBeExamineStep1(HttpServletRequest httpRequest, @Valid PfActivitySignUpPageReq pageVO) {
        return platformActivitySignUpService.pageByToBeExamineStep1(getSysUser(httpRequest), pageVO);
    }

    /**
     * 审核报名资料(一级) - 审核
     **/
    @RequestMapping(value = "/examine/step1", method = RequestMethod.POST)
    public Wrapper<Void> examineStep1(HttpServletRequest httpRequest, @RequestBody @Valid PfActivityExamineSignUpReq req) {
        return platformActivitySignUpService.examineStep1(getSysUser(httpRequest), req);
    }

    /**
     * 审核报名资料(一级) - 批量审核
     **/
    @RequestMapping(value = "/examine/step1/batch", method = RequestMethod.POST)
    public Wrapper<Void> examineStep1Batch(HttpServletRequest httpRequest, @RequestBody @Valid PfActivitySingUpIdsReq req) {
        return platformActivitySignUpService.examineStep1batch(getSysUser(httpRequest), req);
    }

    /**
     * 待审核报名资料(二级)  - 分页列表
     **/
    @RequestMapping(value = "/page/tobe/examine/step2", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpExamPageResp>> pageByToBeExamineStep2(HttpServletRequest httpRequest, @Valid PfActivitySignUpPageReq pageVO) {
        return platformActivitySignUpService.pageByToBeExamineStep2(getSysUser(httpRequest), pageVO);
    }

    /**
     * 审核报名资料(二级) - 审核
     **/
    @RequestMapping(value = "/examine/step2", method = RequestMethod.POST)
    public Wrapper<Void> examineStep2(HttpServletRequest httpRequest, @RequestBody @Valid PfActivityExamineSignUpReq req) {
        return platformActivitySignUpService.examineStep2(getSysUser(httpRequest), req);
    }

    /**
     * 审核报名资料(二级) - 批量审核
     **/
    @RequestMapping(value = "/examine/step2/batch", method = RequestMethod.POST)
    public Wrapper<Void> examineStep2(HttpServletRequest httpRequest, @RequestBody @Valid PfActivitySingUpIdsReq req) {
        return platformActivitySignUpService.examineStep2batch(getSysUser(httpRequest), req);
    }

    /**
     * 待提交报名资料  - 分页列表
     **/
    @RequestMapping(value = "/page/tobe/submit/sign/up", method = RequestMethod.GET)
    public Wrapper<PageData<PfActivitySignUpSubmitPageResp>> pageByToBeSubmitSignUp(HttpServletRequest httpRequest, @Valid PfActivitySignUpPageReq pageVO) {
        return platformActivitySignUpService.pageByToBeSubmitSignUp(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交报名资料 - 提交
     **/
    @RequestMapping(value = "/submit/sign/up", method = RequestMethod.POST)
    public Wrapper<Void> submitSignUp(@RequestBody @Valid PfActivitySingUpIdReq req) {
        return platformActivitySignUpService.submitSignUp(getSysUser(), req.getId());
    }

    /**
     * 待提交报名资料 - 批量提交
     */
    @PostMapping(value = "/submit/sign/up/batch")
    public Wrapper<Void> submitSignUpBatch(@Valid @RequestBody PfActivitySingUpIdsReq req) {
        return platformActivitySignUpService.submitSignUpBatch(getSysUser(), req.getIds());
    }
}
